package com.zf.yichat.controller.plant;

import com.github.pagehelper.PageHelper;
import com.zf.yichat.controller.BaseController;
import com.zf.yichat.model.PrintTreeLevelConfig;
import com.zf.yichat.service.PlantTreeService;
import com.zf.yichat.utils.response.FsResponse;
import com.zf.yichat.utils.response.FsResponseGen;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 碳能量
 */
@Controller
@RequestMapping("plantTree")
@Slf4j
public class PlantTreeController extends BaseController {

    @Resource
    private PlantTreeService plantTreeService;


    /*******************页面访问开始********************************/

    /**
     * 树列表
     * @return
     */
    @RequestMapping("/plant/index")
    public String userLevelIndex() {
        return "plant/index";
    }

    /**
     * 新增树列表
     * @return
     */
    @RequestMapping("/plant/add")
    public String userLevelAdd() {
        return "plant/add";
    }

    /**
     * 编辑树列表
     * @return
     */
    @RequestMapping("/plant/editTree")
    public String userLevelEdit(Long id) {
        PrintTreeLevelConfig level = plantTreeService.selectLevelById(id);
        getRequest().setAttribute("level", level);
        return "plant/edit";
    }

    /*******************页面访问结束********************************/

    /**
     * 查询树列表
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/plant/list")
    @ResponseBody
    public FsResponse levelList(Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        return plantTreeService.selectLevelList();

    };

    /**
     * 新增树列表
     * @param level
     * @return
     */
    @RequestMapping("/plant/save")
    @ResponseBody
    public FsResponse save(PrintTreeLevelConfig level) {
        plantTreeService.addTreeLevel(level);
        return FsResponseGen.success();
    };

    /**
     * 编辑树列表
     * @param level
     * @return
     */
    @RequestMapping("/plant/edit")
    @ResponseBody
    public FsResponse edit(PrintTreeLevelConfig level) {
        plantTreeService.editTreeLevel(level);
        return FsResponseGen.success();
    };


    /**
     * 删除树列表
     * @param id
     * @return
     */
    @RequestMapping("/plant/delete")
    @ResponseBody
    public FsResponse delete(Integer id) {
        plantTreeService.deleteTreeLevel(id);
        return FsResponseGen.success();
    };

}
